package com.zhixun.mobile.modules.goods.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alipay.client.security.MD5Signature;
import com.alipay.client.util.EncodeUtils;
import com.boxin.framework.base.dao.DaoHelper;
import com.zhixun.mobile.common.utils.EncryptUtils;


/**
 * @author Administrator
 * @date 2014-2-26
 * @function <p> ��Ʒ������ </p>
 */
@Service
public class GoodsService {
	
	@Autowired
	DaoHelper daoHelper;
	
	

	/**
	 * @author Jakemanse
	 * @time 2014-2-27  ����10:02:33
	 * @function <p> ��Ʒ�б�  </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> findGoodsList(Map<String,Object> params){
		params.put("encodeKey", EncodeUtils.GOODS_ID_ENCODE_KEY);
		return addEncryptColumn((List<Map<String,Object>>)daoHelper.queryForList("com.zhixun.mobile.goods.selectGoods", params));
	}
	
	
	/**
	 * @author Jakemanse
	 * @time 2014-2-28  ����3:06:59
	 * @function <p> ���� ID�ֶ�</p>
	 * @param result
	 * @return
	 */
	private List<Map<String,Object>> addEncryptColumn(List<Map<String,Object>> result){
		if(result != null && !result.isEmpty()){
			for(Map<String,Object> map : result){
				String id = map.get("id").toString();
				String md5 = EncryptUtils.MD5EncodeString(id+EncodeUtils.GOODS_ID_ENCODE_KEY);
				map.put("encodeId", md5);
			}
		}
		
		return result;
		
	}
	
	
	/**
	 * @author Jakemanse
	 * @time 2014-2-28  ����3:06:12
	 * @function <p> ���涩����Ϣ </p>
	 * @param params
	 */
	public void saveGoodsOrder(Map<String,Object>  params){
		daoHelper.insert("com.zhixun.mobile.goods.saveGoodsOrder", params);
	}
	
	
	
	/**
	 * @author Jakemanse
	 * @time 2014-2-28  ����3:06:31
	 * @function <p>  </p>
	 * @param id
	 * @return
	 */
	public Map<String,Object> getGoodsById(Long id){
		return ( Map<String,Object> )daoHelper.queryForObject("com.zhixun.mobile.goods.getGoodsById", id);
	}
	

}
